<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>连旅物联后台管理系统</title>
<link href="${contextPath}/bootstrap2.3.2/css/bootstrap.min.css"
	rel="stylesheet" />
<link href="${contextPath}/styles/Common.css" rel="stylesheet" />
<link href="${contextPath}/styles/main.css" rel="stylesheet" />
<style type="text/css">
body {
	background-color: #A2A9B4;
	border: solid #fff 0px;
	font-family: 'Microsoft YaHei';
}

.bg {
	background-color: #A2A9B4;
	border: 0px;
}

.top {
	background-color: #414D5F;
}

.left {
	background-color: #414D5F;
}

.no-top-border {
	border-top: 0px;
	background-color: #5D6877;
}

.menu-font {
	font-size: 18px;
	color: #FFFFFF;
}
.tips {
	color: #f00;
}

.input {
	padding-top: 5px;
}

.col-center-block {
	float: none;
	display: block;
	margin-left: auto;
	margin-right: auto;
}

.has-error .form-control {
	border-color: #a94442;
	-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
}

.hax-error label {
	color: #a94442
}

.link:HOVER {
	cursor: pointer;
	color: #57d3ac;
}

.setting:hover {
	cursor: pointer;
	background-image: url("${contextPath}/images/menu_settings_hover.png");
	background-repeat:no-repeat;
	width: 36px;
	height: 36px;
}

.foot-wrap{
	background-color: #eae5e5;
	margin-top:1px;
	text-align: center;
}
</style>
</head>

<body>
	<div class="header top">
		<img class="logo" src="${contextPath}/images/menu_logo.png" /> <label
			class="logo-title">智能锁后台管理系统V1.0</label>
		<ul class="inline">
			<c:choose>
				<c:when test="${!empty USER_SESSION_INFO}">
					<li>
						<!-- <img src="${contextPath}/images/32/client.png" />&nbsp;-->&nbsp;欢迎您&nbsp;${USER_SESSION_INFO.user_name}
					</li>
					<li class="link" data-toggle="modal" data-target="#updateInfoModal"><img
						src="${contextPath}/images/menu_passwd.png" />&nbsp;&nbsp;修改密码</li>
					<li onclick="javascript:loginOut()" class="link"><img
						src="${contextPath}/images/menu_exit.png" />&nbsp;&nbsp;退出</li>
				</c:when>
				<c:otherwise>
					<li><img src="${contextPath}/images/32/client.png" /><a
						href="${contextPath}">登录</a></li>
				</c:otherwise>
			</c:choose>
		</ul>
	</div>
	<%-- <div class="nav">
		<ul class="breadcrumb">
			<li><img src="${contextPath}/images/32/5025_networking.png" />
			</li>
			<li><a href="#">首页</a> <span class="divider">>></span></li>
			<li class="active"></li>
		</ul>
	</div> --%>
	<div class="container-fluid content">
		<div class="row-fluid">
			<div class="span2 content-left accordion left">

				<%-- <div class="accordion-group">
					<div class="accordion-heading">
						<a class="accordion-toggle" data-toggle="collapse"
							data-parent="#accordion2" href="#collapseOne"> <img
							class="left-icon"
							src="${contextPath}/images/menu_home.png" /><span
							class="left-title">主页</span>
						</a>
					</div> --%>
					<div class="accordion-inner no-top-border">
						<img class="left-icon-child" src="${contextPath}/images/menu_home.png" /><span
							class="left-body menu-font" href="${contextPath}/redirect/welcome.lt"> 主页</span>
					</div>

					<!-- 	<div id="collapseOne" class="accordion-body collapse in"> -->
					<div class="accordion-inner no-top-border">
						<img class="left-icon-child"
							src="${contextPath}/images/menu_settings.png" /><span
							class="left-body menu-font" href="${contextPath}/redirect/deviceslist.lt">
							锁管理</span>
					</div>
					<div class="accordion-inner no-top-border">
						<img class="left-icon-child"
							src="${contextPath}/images/menu_record.png" /><span
							class="left-body menu-font"
							href="${contextPath}/redirect/devicesloglist.lt"> 锁记录</span>

				</div>
				<div class="accordion-inner no-top-border">
					<img class="left-icon-child"
						src="${contextPath}/images/menu_message.png" /><span
						class="left-body menu-font"
						href="${contextPath}/redirect/smslist.lt"> 短信统计</span>
				</div>
				<div class="accordion-inner no-top-border">
					<img class="left-icon-child"
						src="${contextPath}/images/menu_message.png" /><span
						class="left-body menu-font"
						href="${contextPath}/redirect/upgrade.lt"> 软件升级</span>
				</div>
				<div class="accordion-inner no-top-border">
					<img class="left-icon-child"
						src="${contextPath}/images/menu_message.png" /><span
						class="left-body menu-font"
						href="${contextPath}/redirect/tools.lt"> 维护工具</span>
				</div>
				<%-- 
						<div class="accordion-inner">
							<img class="left-icon-child"
								src="${contextPath}/images/32/612.png" /><span
								class="left-body"> 单位管理</span>
						</div>
						<div class="accordion-inner">
							<img class="left-icon-child" src="${contextPath}/images/32/8.png" /><span
								class="left-body"> 字典管理</span>
						</div>
						 --%>
					<!-- </div> 
				</div>-->

			</div>

			<div class="span10 content-right bg">
				<iframe id="maincontent" src="${contextPath}/redirect/welcome.lt"
					class="iframe"></iframe>
			</div>
		</div>
	</div>



	<!-- ADD -->
	<!-- 模态框（Modal） -->
	<div class="modal fade" id="updateInfoModal" tabindex="-1"
		role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">修改密码</h4>
				</div>
				<div class="modal-body">
					<form id="updateUserInfo" class="form-horizontal" role="form"
						method="post" action="${contextPath}/service/device/addDevice.lt">
					<%-- 	<div class="form-group input">
							<label for="firstname" class="col-sm-2 control-label input"><span
								class="tips">*</span> 用户名</label>&nbsp;&nbsp; <input type="text"
								class="form-control" id="user_name" name="user_name"
								value="${USER_SESSION_INFO.user_name}" placeholder="请输入原密码"
								readonly="readonly">

						</div> --%>
						<div class="form-group input" id="group_user_pwd">
							<label for="firstname" class="col-sm-2 control-label input"><span
								class="tips">*</span> 原密码</label>&nbsp;&nbsp; <input type="password"
								class="form-control" id="user_pwd" name="user_pwd" value=""
								placeholder="请输入原密码">

						</div>
						<div class="form-group input" id="group_user_pwd_new">
							<label for="lastname" class="col-sm-2 control-label input"><span
								class="tips">*</span> 新密码</label>&nbsp;&nbsp; <input type="password"
								class="form-control" id="user_pwd_new" name="user_pwd_new"
								placeholder="请输入新密码">

						</div>
						<div class="form-group input" id="group_repeat_pwd">
							<label for="lastname" class="col-sm-2 control-label input"><span
								class="tips">*</span> 确认密码</label>&nbsp;&nbsp; <input type="password"
								class="form-control" id="repeat_pwd" name="repeat_pwd"
								placeholder="请再次输入新密码">

						</div>
					</form>
					<div id="divalert"></div>
					<div id="divsuccess"></div>
				</div>
				<div class="modal-footer">
					<!-- <button type="button" class="btn btn-default" data-dismiss="modal">关闭
					</button> -->
					<button id="btn_updatesave" type="button" class="btn btn-primary"
						onclick="javascript:updateUserInfo()">保存</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal -->
	</div>
	<!-- ADD -->



	<div class="clearfix"></div>
	<div class="foot"></div>
	<footer class="container foot-wrap bg">
    <!-- 采用container，使得页尾内容居中 -->
        <div class="bg">
        copyright&copy;Shanghai LinkTrip IoT Technology&nbsp;Co.,Ltd
        </div>
     </footer>
	<script src="${contextPath}/scripts/jquery-1.9.1.min.js"></script>
	<script src="${contextPath}/bootstrap2.3.2/js/bootstrap.min.js"></script>
	<script src="${contextPath}/scripts/frame.js"></script>
	<script src="${contextPath}/js/tools.js"></script>
	<script type="text/javascript">
		function updateUserInfo() {
			var userName = $("#user_name").val();
			var pwd = $("#user_pwd").val();
			var pwd_new = $("#user_pwd_new").val();
			var repeat_pwd = $("#repeat_pwd").val();
			var exp = new RegExp("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,10}$");

			if(pwd == ""){
				alertPopu("divalert", "原密码不能为空!");
				$("#group_user_pwd").addClass("has-error");
				return;
			}else if (exp.test(pwd) == false) {
				alertPopu("divalert", "密码必须是6-10位数字加字母!");
				$("#group_user_pwd").addClass("has-error");
				return;
			} else {
				$("#group_user_pwd").removeClass("has-error");
			}
			
			if(pwd_new == ""){
				alertPopu("divalert", "新密码不能为空!");
				$("#group_user_pwd_new").addClass("has-error");
				return;
		    }else if (exp.test(pwd_new) == false) {
				alertPopu("divalert", "新密码必须是6-10位数字加字母!");
				$("#group_user_pwd_new").addClass("has-error");
				return;
			} else {
				$("#group_user_pwd_new").removeClass("has-error");
			}

			if (pwd_new != repeat_pwd) {
				alertPopu("divalert", "两次新密码输入不一致!");
				$("#group_user_pwd_new").addClass("has-error");
				$("#group_repeat_pwd").addClass("has-error");
				return;
			} else {
				$("#group_user_pwd_new").removeClass("has-error");
				$("#group_repeat_pwd").removeClass("has-error");

			}

			if (pwd == repeat_pwd) {
				alertPopu("divalert", "新密码不能与原密码相同!");
				$("#group_repeat_pwd").addClass("has-error");
				return;
			} else if(pwd != '${USER_SESSION_INFO.user_passwd}'){
				alertPopu("divalert", "原密码输入有误!");
				$("#group_user_pwd").addClass("has-error");
				return;
		     }else {
				$("#group_repeat_pwd").removeClass("has-error");
			}

			$("#btn_updatesave").attr("data-dismiss", "modal");
			var formdata = {
				pwd : pwd,
				pwd_new : pwd_new
			};

			$.ajax({
				url : "${contextPath}/service/user/updateUserPWD.lt",
				timeout : 30000,
				dataType : "json",
				type : "post",
				data : formdata,
				success : function(data) {
					var msg = "";
					if (data == 200) {
						msg = "修改成功!";
						$("#user_name").val("");
						$("#user_pwd").val("");
						$("#user_pwd_new").val("");
						$("#repeat_pwd").val("");
						alertPopu("divalert", "");
					} else if (data == 400) {
						msg = "密码不匹配!";
						$("#user_name").val("");
						$("#user_pwd").val("");
						$("#user_pwd_new").val("");
						$("#repeat_pwd").val("");
						alertPopu("divalert", "");
					} else {
						msg = "修改失败";
					}
					showBox(msg);
				},
				error : function(req, msg, err) {
					alertPopu("divalert", "修改失败!");
				}
			});

		}

		function loginOut() {
			if (confirm("确定要退出?")) {
				location.href = "${contextPath}/service/user/loginOut.lt";
			}
		}
	</script>
</body>
</html>
